package com.motherchild.admin.controller;

import com.motherchild.admin.dto.RoleDTO;
import com.motherchild.admin.service.RoleService;
import com.motherchild.common.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/roles")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("/getRoleList")
    public ApiResponse<List<RoleDTO>> getAllRoles() {
        List<RoleDTO> roles = roleService.getAllRoles();
        return ApiResponse.success(roles);
    }

    @PostMapping("/addRole")
    public ApiResponse<Void> addRole(@RequestBody RoleDTO roleDTO) {
        roleService.addRole(roleDTO);
        return ApiResponse.success();
    }

    @PutMapping("/updateRole/{id}")
    public ApiResponse<Void> updateRole(@PathVariable Long id, @RequestBody RoleDTO roleDTO) {
        roleDTO.setId(id);
        roleService.updateRole(roleDTO);
        return ApiResponse.success();
    }

    @DeleteMapping("/deleteRole/{id}")
    public ApiResponse<Void> deleteRole(@PathVariable Long id) {
        roleService.deleteRole(id);
        return ApiResponse.success();
    }
} 